

package com.hazelcast.nio.serialization.compatibility;

import com.hazelcast.nio.serialization.ByteArraySerializer;

import java.nio.ByteBuffer;

public class CustomByteArraySerializer implements ByteArraySerializer<CustomByteArraySerializable> {

    @Override
    public int getTypeId() {
        return ReferenceObjects.CUSTOM_BYTE_ARRAY_SERIALIZABLE_ID;
    }

    @Override
    public byte[] write(CustomByteArraySerializable object) {
        byte[] bytes = new byte[10];
        ByteBuffer wrap = ByteBuffer.wrap(bytes);
        wrap.putInt(object.i);
        wrap.putFloat(object.f);
        return bytes;
    }

    @Override
    public CustomByteArraySerializable read(byte[] buffer) {
        ByteBuffer wrap = ByteBuffer.wrap(buffer);
        return new CustomByteArraySerializable(wrap.getInt(), wrap.getFloat());
    }

}
